package com.tiku.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tiku.common.ResultJson;
import com.tiku.entity.ExamPaper;
import com.tiku.entity.UserPayTiku;
import com.tiku.service.ExamPaperService;
import com.tiku.mapper.ExamPaperMapper;
import com.tiku.service.UserPayTikuService;
import com.tiku.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 *
 */
@Service
public class ExamPaperServiceImpl extends ServiceImpl<ExamPaperMapper, ExamPaper>
    implements ExamPaperService{

    @Autowired
    private ExamPaperMapper examPaperMapper;

    @Autowired
    private UserPayTikuService userPayTikuService;
    @Override
    public ResultJson examList(String exam,String specification) {
        String userId = ThreadLocalUtil.getThreadLocal();
        List<ExamPaper> examPapers = examPaperMapper.selectList(new QueryWrapper<ExamPaper>().select("DISTINCT * ").lambda().eq(ExamPaper::getMenuId, exam));
        UserPayTiku tiku = userPayTikuService.getOne(new LambdaQueryWrapper<UserPayTiku>().eq(UserPayTiku::getUserId, userId)
                .eq(UserPayTiku::getPaySpecId,specification));
        if (!Objects.isNull(tiku)){
            for (ExamPaper examPaper : examPapers) {
                examPaper.setFreeFlag("0");
            }
        }
        return ResultJson.success(examPapers);

    }
}




